package com.course.servlet;

import com.course.entity.Teacher;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

@WebServlet("/laoshi_personal_center")
public class LaoshiPersonalCenterServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        request.setCharacterEncoding("UTF-8");

        HttpSession session = request.getSession(false); // Do not create a new session if one doesn't exist
        Teacher teacher = null;

        if (session != null) {
            teacher = (Teacher) session.getAttribute("teacher");
        }

        if (teacher == null) {
            response.sendRedirect(request.getContextPath() + "/laoshi_login.jsp");
            return;
        }

        request.setAttribute("teacher", teacher);
        request.getRequestDispatcher("/laoshi_personal_center.jsp").forward(request, response);
    }
} 